package com.lingshi.yingzaitownmap.controller;

import com.lingshi.yingzaitownmap.entity.domain.Attraction;
import com.lingshi.yingzaitownmap.entity.domain.Restaurant;
import com.lingshi.yingzaitownmap.entity.domain.Shops;
import com.lingshi.yingzaitownmap.entity.result.Result;
import com.lingshi.yingzaitownmap.service.AttractionService;
import com.lingshi.yingzaitownmap.service.RestaurantService;
import com.lingshi.yingzaitownmap.service.ShopsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 地图相关接口
 */
@RestController
@RequestMapping("/api/v1/map")
@Slf4j
@RequiredArgsConstructor
@Validated
public class MapController {

    private final AttractionService attractionService;
    private final ShopsService shopsService;
    private final RestaurantService restaurantService;

    /**
     * 获取所有 景点、商铺、饭店 的坐标
     */
    @GetMapping("/points")
    public Result getMapPoints(){
        // 日志
        log.info("获取所有 景点、商铺、饭店 的坐标");
        // 总集合
        List list = new ArrayList();
        // 查询所有景点
        List<Attraction> attractionList = attractionService.query()
                .select("id","name","latitude","longitude").list();
        // 查询所有商铺
        List<Shops> shopsList = shopsService.query()
                .select("id","name","latitude","longitude").list();
        // 查询所有饭店
        List<Restaurant> restaurantList = restaurantService.query()
                .select("id","name","latitude","longitude").list();
        // 汇总到总集合
        list.addAll(attractionList);
        list.addAll(shopsList);
        list.addAll(restaurantList);
        // 返回
        return Result.success(list);
    }

}
